package com.lfd.kafka.service;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @项目名： spring-emq
 * @包名： com.lfd.kafka.service
 * @文件名: KafkaConsumer
 * @创建者: liufudong@szyh-smart.com
 * @创建时间: 2024/9/30 16:57
 * @描述：4. 创建 Kafka 消费者 创建一个 Kafka 消费者类，用于接收消息：
 */
@Slf4j
@Service
public class KafkaConsumer {
    @KafkaListener(topics = "your-topic-name", groupId = "your-consumer-group")
    public void listen(String message) {
        log.info("listen message: {}", message);
    }
//    @KafkaListener(groupId = "helloGroup", topics = "helloTopic")
//    public void onEvent(List<ConsumerRecord<String, String>> records) {
//        System.out.println("批量消费，records.size() = " + records.size() + "，records = " + records);
//    }

}
